package demo;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

/**
 * 客户端程序
 */
public class Client {

    public static void main(String[] args)  {

        Client client = new Client();
        try {
            client.fun1();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }

    private void fun1() throws IOException {

        //创建Scanner对象
        Scanner sc = new Scanner(System.in);
        while(true){
            //1、创建客户端Socket对象
            Socket socket = new Socket("localhost",8080);
            //2、获取输出流对象
            OutputStream out = socket.getOutputStream();
            //3、通过输出流对象写出数据
            //获取输入的内容  next()：用于获取输入的字符串(以空格为标记进行获取)   nextLine():用于获取输入的字符串(以回车为标记进行获取)
            String words = sc.next();
            if("886".equals(words)||"over".equals(words)){
                //4、释放资源
                out.close();
                socket.close();
                break;
            }
            out.write(words.getBytes());
            //4、释放资源
            out.close();
            socket.close();
        }

    }

}